package cn.javass.dp.flyweight.demo1;

import java.util.HashMap;
import java.util.Map;

public class FlyweightFactory {

    private static Map<String, Flyweight> pool = new HashMap<>();

    public static Flyweight getFlyweight(String extrinsic) {
        Flyweight flyweight = null;
        if (pool.containsKey(extrinsic)) {
            flyweight = pool.get(extrinsic);
            System.out.println("已有");
        } else {
            flyweight = new ConcreateFlyweight(extrinsic);
            pool.put(extrinsic, flyweight);
            System.out.println("创建" + extrinsic + "并从池中取出");
        }
        return flyweight;
    }



}
